<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%@ include file="/common/grid/jqGrid.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="This is my page">
	
  </head>
  
  <body>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'调查问卷'},{'name':'问卷定义'}]"/>
    			<jsp:param name="width" value="40%"/>
    		</jsp:include>
    		
    		<table cellspacing="1" width="100%" bgcolor="#CCCCCC">
				<tr bgcolor="#FFFFFF">
					<td align="right" width="10%" class="label">
						问卷编号：
					</td>
					<td align="left" width="23%">
						<s:textfield id="paperCode" cssStyle="width:80%" cssClass="search"></s:textfield>
					</td>
					<td align="right" width="10%" class="label">
						问卷名称：
					</td>
					<td align="left" width="23%">
						<s:textfield id="paperName" cssStyle="width:80%" cssClass="search"></s:textfield>
					</td>
					<td align="right" width="10%" class="label">
						时间：
					</td>
					<td align="left" width="24%">
						<s:textfield id="paperTimeStart" cssStyle="width:100px" cssClass="search WDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"></s:textfield>
						-
						<s:textfield id="paperTimeEnd" cssStyle="width:100px" cssClass="search WDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"></s:textfield>
					</td>
				</tr>
			</table>
			<table cellspacing="0" width="100%">
				<tr>
					<td align="left">
    					<input type="button" value="新增" class="btn" onclick="addPaper()" />
    					<input type="button" value="查询" class="btn" onclick="searchThis()" />
    					<input type="button" value="重置" class="btn" onclick="resetSearch()" />
    				</td>
    			</tr>
    		</table>
    		<table id="list" cellpadding="3" cellspacing="0"></table>
			<div id="pager" style="text-align:center;"></div>
    	</s:form>
    
    <script type="text/javascript">
    $(document).ready(function(){
        var cName = new Array('问卷编号','问卷名称', '半开放题行数', '全开放题行数', '时间', '操作');
    	var cModel = [
    					{name:'paperCode', index:'paperCode', width:'15%', align:'center'},  
    					{name:'paperName', index:'paperName', width:'22%', align:'center'},
                        {name:'halfQesRow', index:'halfQesRow', width:'15%', align:'center'},
                        {name:'fullQesRow', index:'fullQesRow', width:'15%', align:'center'},
                        {name:'paperTime', index:'paperTime', width:'15%', align:'center', formatter:'date', formatoptions:{newformat:'Y-m-d'}},
                        {name:'id', index:'id', width:'18%', align:'center', sortable:false, formatter:option}
                      ];
        
        newJqGrid({
        	id: 'id',
        	gridId: 'list',
        	pagerId: 'pager',
        	url: 'inner/qes/paperDefineListByPage.action',
        	head: cName,
        	column: cModel,
        	width: getBodyWidth(),
        	height: 'auto',
        	hasCb: false,
        	title: '问卷列表'
        });
        
        $(window).resize(function(){
        	gridAutoWidth('list', 'win');
        });
    });
    
    function option(cellVal, options, row)
    {
    	var html = '<a href="javascript:updatePaper(\'' + row['id'] + '\')" >修改</a>';
    	html += ' <a href="javascript:delPaper(\'' + row['id'] + '\')" >删除</a>';
    	html += ' <a href="javascript:exportPaperMap(\'' + row['id'] + '\')" >导出</a>';
    	return html;
    }
    
    function updatePaper(id)
    {
    	var url = realPath + '/inner/qes/toUpdatePaper.action?paper.id=' + id;
    	window.location.href = url;
    }
    
    function delPaper(id)
    {
    	showConfirm('确认删除？', function(v){
    		if(v == true)
    		{
    			ajaxAction('inner/qes/delPaper.action?paper.id=' + id, 'get', 'frm', true, function(msg){
    				if('error' == msg)
    				{
    					showMsg('删除失败，该问卷已应用。');
    				}
    				else
    				{
   						searchThis();
    				}
    			});
    		}
    	});
    }
    
    function exportPaperMap(id)
    {
    	document.forms['frm'].target = '_blank';
    	document.forms['frm'].action = realPath + '/inner/qes/exportPaperMap.action?paper.id=' + id;
    	document.forms['frm'].submit();
    }
    
    function searchThis()
    {
    	var params = {
    		'pvo.paperName':$('#paperName').val(),
    		'pvo.paperCode':$('#paperCode').val(),
    		'pvo.paperTimeStart':$('#paperTimeStart').val(),
    		'pvo.paperTimeEnd':$('#paperTimeEnd').val()
    	};
    	toSearchList('list', params);
    }
    
    function addPaper()
    {
    	var url = realPath + '/inner/qes/toAddPaper.action';
    	openWin(url, 700, 300, 'yes', 'yes');
    }
    </script>
  </body>
</html>
